# Author    : CoffeeChicken
# Date      : 2020-10-22 10:02
# Function  : 演示 演示使用多线程

import threading
import time

num = 0
lock = threading.Lock()


def run1():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run2():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run3():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run4():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run5():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run6():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run7():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run8():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run9():
    global num
    for i in range(100000000):
        lock.acquire()
        num += 1
        lock.release()


def run10():
    global num
    for i in range(100000):
        num += 1


if __name__ == '__main__':
    start = time.time()

    t1 = threading.Thread(target=run1)
    t2 = threading.Thread(target=run2)
    # t3 = threading.Thread(target=run3)
    # t4 = threading.Thread(target=run4)
    # t5 = threading.Thread(target=run5)
    # t6 = threading.Thread(target=run6)
    # t7 = threading.Thread(target=run7)
    # t8 = threading.Thread(target=run8)
    # t9 = threading.Thread(target=run9)
    # t10 = threading.Thread(target=run10)

    t1.start()
    t2.start()
    # t3.start()
    # t4.start()
    # t5.start()
    # t6.start()
    # t7.start()
    # t8.start()
    # t9.start()

    # end = time.time()

    time.sleep(20)
    print(num)
    # print("====> total time", end - start, "<<====")
    # t10.start()

    # print("=====>>>> OK <<<<======")
# total time 0.002086162567138672
